package com.itheima;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;

/**
 * @author zhangbaiyan
 * @date 2024-08-24 19:56
 * @description:
 * @version:
 */
public class 综合 {

    public static void main(String[] args) throws ParseException {
        //请使用代码实现计算你活了多少天,用JDK7和JDK8的两种方式实现
        //JDK7
        String birthday="1999-08-24";
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date date = df.parse(birthday);
        long time = date.getTime();
        long day = (System.currentTimeMillis() - time) / (1000 * 60 * 60 * 24);
        System.out.println("活了"+day+"天");

        //JDK8
        LocalDate localDate = LocalDate.now();
        LocalDate localDate1 = LocalDate.parse(birthday);
//        LocalDate localDate1 = LocalDate.of(1999,8,24);
        long days = localDate.toEpochDay() - localDate1.toEpochDay();
        System.out.println("活了"+days+"天");
    }
}
